<template>
	<xn-form-container
		:title="'查看软件版本'"
		:width="700"
		v-model:open="open"
		:destroy-on-close="true"
		@close="onClose"
	>
		<a-form ref="formRef" :model="formData" :rules="formRules" layout="horizontal">
			<a-form-item label="版本标识：" name="version">
				{{ formData.version }}
			</a-form-item>
			<a-form-item label="名称：" name="name">
				{{ formData.name }}
			</a-form-item>
			<a-form-item label="说明：" name="description">
				{{ formData.description }}
			</a-form-item>
			<a-form-item label="生成类型：" name="builderType">
				{{ formData.builderType }}
			</a-form-item>
			<a-form-item label="程序路径：" name="path">
				{{ formData.path }}
			</a-form-item>
			<a-form-item label="生成脚本执行命令：" name="scriptName">
				{{ formData.scriptName }}
			</a-form-item>
			<a-form-item label="用户信息文件名：" name="userInfoFileName">
				{{ formData.userInfoFileName }}
			</a-form-item>
			<a-form-item label="配置文件文件名：" name="configFileName">
				{{ formData.configFileName }}
			</a-form-item>
			<a-form-item label="授权文件产物名：" name="licenseFileName">
				{{ formData.licenseFileName }}
			</a-form-item>
		</a-form>
		<template #footer>
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
		</template>
	</xn-form-container>
</template>

<script setup name="softwareVersionForm">
	import tool from '@/utils/tool'
	import { cloneDeep } from 'lodash-es'
	import { required } from '@/utils/formRules'
	import softwareVersionApi from '@/api/biz/softwareVersionApi'
	// 抽屉状态
	const open = ref(false)
	const emit = defineEmits({ successful: null })
	const formRef = ref()
	// 表单数据
	const formData = ref({})
	const submitLoading = ref(false)
	const builderTypeOptions = ref([])

	// 打开抽屉
	const onOpen = (record) => {
		open.value = true
		if (record) {
			let recordData = cloneDeep(record)
			formData.value = Object.assign({}, recordData)
		}
		builderTypeOptions.value = tool.dictList('BUILD_TYPE')
	}
	// 关闭抽屉
	const onClose = () => {
		formRef.value.resetFields()
		formData.value = {}
		open.value = false
	}
	// 默认要校验的
	const formRules = {}
	// 验证并提交数据
	const onSubmit = () => {
		formRef.value
			.validate()
			.then(() => {
				submitLoading.value = true
				const formDataParam = cloneDeep(formData.value)
				softwareVersionApi
					.softwareVersionSubmitForm(formDataParam, formDataParam.id)
					.then(() => {
						onClose()
						emit('successful')
					})
					.finally(() => {
						submitLoading.value = false
					})
			})
			.catch(() => {})
	}
	// 抛出函数
	defineExpose({
		onOpen
	})
</script>
